package frame.networks.viewers;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import model.components.links.link.Link;
import model.components.networks.network.PhysicalNetwork;
import model.components.nodes.node.Node;

import edu.uci.ics.jung.algorithms.layout.Layout;
import frame.MopraFrame;
import frame.networks.viewers.viewer.NetworkVisualizationViewer;

@SuppressWarnings("serial")
public class PhysicalNetworksVisualizationViewersTabbedPane extends JTabbedPane
{
	private MopraFrame mopraFrame;
	public MopraFrame getFrame(){ return mopraFrame; }
	public void setFrame( MopraFrame mopraFrame ){ this.mopraFrame = mopraFrame; }

	public PhysicalNetworksVisualizationViewersTabbedPane( MopraFrame mopraFrame )
	{
		this.setFrame( mopraFrame );
		
		this.setTabPlacement( SwingConstants.TOP );
		
		for( PhysicalNetwork physicalNetwork: mopraFrame.getSimulator().getPhysicalNetworks() )
			this.addPhysicalNetworkTab( physicalNetwork );
	}
	
	public void addPhysicalNetworkTab( PhysicalNetwork physicalNetwork )
	{
		Layout< Node, Link > layout = physicalNetwork.getLayout();
		layout.setGraph( physicalNetwork.getGraph() );
		
		NetworkVisualizationViewer networkVisualizationViewer = new NetworkVisualizationViewer( layout, this.getFrame() );
		networkVisualizationViewer.setBackground( Color.WHITE );
		
		JPanel panel = new JPanel( new BorderLayout() );
		panel.add( networkVisualizationViewer );
		
		this.addTab( physicalNetwork.getName(), null, panel, "Physical network " + physicalNetwork.getNumber() );
	}
}
